﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEngine.UI;

namespace Nirvana
{
    [AddComponentMenu("Nirvana/UI/Language/Scale I18N")]
    [DisallowMultipleComponent]
    [ExecuteInEditMode]
    public sealed class ScaleI18N : Translatable
    {
        [Serializable]
        private struct BindLanguageScale
        {
            [Tooltip("The languaget type.")]
            public I18NLanguageType languagetype;
            [Tooltip("The translate scale.")]
            public float translate;
        };

        /// <summary>
        /// 内置翻译表，不通过keyid获取，直接设置
        /// </summary>
        [SerializeField]
        [Tooltip("The bind Language Scale list.")]
        private List<BindLanguageScale> binds = new List<BindLanguageScale>();

        protected override void TranslateText()
        {
            this.GetTranslate();
        }

        private  void GetTranslate()
        {
            I18NLanguageType language = I18N.Language;
            foreach (var f in binds)
            {
                if(f.languagetype == language)
                {
                    if (f.translate > 0) this.transform.localScale = Vector3.one * f.translate;
                } 
            }

        }

    }
}

